package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.entity.Bo.AllianceDetailBo;
import com.hzncc.scaffold.entity.Bo.AllianceListBo;
import com.hzncc.scaffold.entity.Other.Alliance;
import com.hzncc.scaffold.entity.Vo.AllianceInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 机构表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Component
public interface AllianceMapper extends BaseMapper<Alliance> {


    @Select("SELECT `id`, `content` FROM `alliance` AS `alliance` LIMIT 1")
    public AllianceInfoVo allianceInfo();


    @Select("SELECT\n" +
            "\t`applianceapply`.`id`,\n" +
            "\t`applianceapply`.`status`,\n" +
            "\t`applianceapply`.`pubTime`,\n" +
            "\t`applianceapply`.`createTime`,\n" +
            "\t`applianceapply`.`stayAtTop`,\n" +
            "\t`institute`.`id` AS `instituteId`,\n" +
            "\t`institute`.`name` AS `instituteName`,\n" +
            "\t`institute`.`role` AS `instituteRole`,\n" +
            "\t`institute`.`logo` AS `instituteLogo` \n" +
            "FROM\n" +
            "\t`applianceapply` AS `applianceapply`\n" +
            "\tLEFT OUTER JOIN `user` AS `institute` ON `applianceapply`.`instituteId` = `institute`.`id` \n" +
            "WHERE\n" +
            "\t`applianceapply`.`status` = 1 \n" +
            "ORDER BY\n" +
            "\t`applianceapply`.`stayAtTop` DESC,\n" +
            "\t`applianceapply`.`sortTime` DESC,\n" +
            "\t`applianceapply`.`id` DESC")
    public List<AllianceListBo> list();



    @Select("SELECT\n" +
            "\t`applianceapply`.`id`,\n" +
            "\t`applianceapply`.`pubTime`,\n" +
            "\t`institute`.`id` AS `instituteId`,\n" +
            "\t`institute`.`name` AS `instituteName`,\n" +
            "\t`institute`.`role` AS `instituteRole`,\n" +
            "\t`institute`.`logo` AS `instituteLogo`,\n" +
            "\t`institute`.`info` AS `instituteInfo` \n" +
            "FROM\n" +
            "\t`applianceapply` AS `applianceapply`\n" +
            "\tINNER JOIN `user` AS `institute` ON `applianceapply`.`instituteId` = `institute`.`id` ${ew.customSqlSegment}")
    public AllianceDetailBo detail(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);
}
